package com.ict.luxshare.jobservice;

import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.PersistableBundle;
import android.util.Log;

import static android.content.Context.JOB_SCHEDULER_SERVICE;

public class BootReceiver extends BroadcastReceiver {
    private final static String TAG = "jb:BootReceiver";
    private Context mContext;
    @Override
    public void onReceive(Context context, Intent intent) {
        String strAction = intent.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(strAction)) {
            Log.d(TAG, "BOOT completed()");
            mContext = context;
            //這邊測試一下，下面的部份先mark起來
//            mContext.startActivity(new Intent(mContext, Empty.class));

            //這邊是新的測試部份
            JobInfo jobInfo;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Log.d(TAG, "onCreate()");
                JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    jobInfo = new JobInfo.Builder(BtJobService.REGISTER_BT_RECEIVER, new ComponentName("com.ict.luxshare.jobservice", BtJobService.class.getName()))
                            .setMinimumLatency(100)
                            .setPersisted(true)
                            .build();
                } else {
                    jobInfo = new JobInfo.Builder(BtJobService.REGISTER_BT_RECEIVER, new ComponentName("com.ict.luxshare.jobservice", BtJobService.class.getName()))
                            .setPeriodic(100)
                            .setPersisted(true)
                            .build();
                }
                jobScheduler.schedule(jobInfo);
            }
        }
    }
}
